import os
import subprocess

'''
    用于运行用户的python脚本
    输入输出是脚本路径，日志输出路径，数据输入路径，数据输出路径
'''


def runPreprocess(preprocess_path, data_dir, out_dir):
    # Run the preprocess.py script
    log_out = os.popen('python ' + preprocess_path + ' ' + data_dir + ' ' + out_dir)
    log_out = log_out.read()

    return log_out


def runPostprocess(postprocess_path, data_dir, out_dir):
    # Run the postprocess.py script
    log_out = os.popen('python ' + postprocess_path + ' ' + data_dir + ' ' + out_dir)
    log_out = log_out.read()

    return log_out


def excuteCommand(com):
    ex = subprocess.Popen(com, stdout=subprocess.PIPE, shell=True)
    out, err = ex.communicate()
    ex.wait()
    return out.decode()
